<template>
  <el-dialog
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    title="下发参数编辑"
    :append-to-body="true"
    :visible="stageVisible"
    custom-class="stage_dialog"
    width="80%"
    @close="close"
  >
    <el-table
      style="margin-top: 10px"
      :data="formulaParameter"
      border
      size="mini"
    >
      <el-table-column
        :prop="item.key"
        :label="item.label"
        align="center"
        v-for="item in _formulaInfo.filter(f => !f.hide)"
        :key="item.label"
        ><template slot-scope="scope">
          <el-input
            v-if="item.type == 'input'"
            v-model="scope.row[item.key]"
            placeholder="请输入"
            size="small"
            clearable
          ></el-input>
          <!-- <el-input
            v-else-if="item.type == 'radio'"
            v-model="scope.row[item.key]"
            placeholder="请输入"
            size="small"
            clearable
          ></el-input> -->
          <el-radio-group
            v-model="scope.row[item.key]"
            v-else-if="item.type == 'radio'"
          >
            <el-radio
              :label="radio.value"
              v-for="radio in item.options"
              :key="radio.value"
              >{{ radio.label }}</el-radio
            >
          </el-radio-group>
          <span v-else>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" fixed="right">
        <template slot="header">
          <div class="flex-x">
            <div style="margin-right: 10px">操作1</div>
            <el-button type="primary" size="small" @click="addFormula"
              >添加</el-button
            >
          </div>
        </template>
        <template slot-scope="scope">
          <el-button type="danger" size="mini" @click="del(scope.$index)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <span slot="footer">
      <el-button
        type="primary"
        :loading="stageBtnloading"
        @click="submit"
        size="small"
        >{{ isIssued ? "确认下发" : "确认修改" }}</el-button
      >
      <el-button @click="close" size="small"> 取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getTaskDownLoadInfos } from "@/api/deviceOperation";
import { generateId } from "@/utils";
import { mapGetters } from "vuex";

import { VACUUM_FORMULA_INFO_Z13 } from "./constant";
export default {
  props: {
    // 是否是下发按钮
    isIssued: {
      type: Boolean,
      default: false
    },
    stageVisible: {
      type: Boolean,
      default: false
    },
    stageBtnloading: {
      type: Boolean,
      default: false
    },
    formulaParameter: {
      type: Array,
      default: () => []
    }
  },
  computed: {
    ...mapGetters(["controlDeviceInfo"]),
    _formulaInfo() {
      return VACUUM_FORMULA_INFO_Z13;
    }
  },

  data() {
    return {
      // formulaParameter: [],
    };
  },
  watch: {},
  mounted() {
    // 获取任务下发弹框列表
    // this.getTaskDownLoadInfos();
  },
  methods: {
    // 删除阶段
    del(index) {
      // this.formulaParameter.splice(index, 1);
      this.$emit("del", index);
    },
    submit() {
      this.$emit("submit");
    },
    addFormula() {
      this.$emit("addFormula");
    },
    close() {
      this.$emit("update:stageVisible", false);
    }
  }
};
</script>

<style lang="scss">
.stage_dialog {
  .el-radio {
    margin-right: 10px;
  }
}
</style>
